﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DependencyParse.Library;
using System.IO;

namespace DependencyParse
{
    public partial class LibraryViewerForm : Form
    {
        public LibraryViewerForm()
        {
            InitializeComponent();
        }

        private void button_Select_Click(object sender, EventArgs e)
        {
            try
            {
                if (mRadio_Class.Checked)
                {
                    mDataView.DataSource = GenerateTempBinding(AssemblyHelper.Load(mTxt_PathName.Text).Classes.ConvertAll(
                        n => new
                        {
                            Name = n.Name,
                            AssemblyName = n.AssemblyName,
                            NameSpace = n.Namespace,
                            FullName = n.FullName,
                            Interfaces = GetInterfaceNames(n),
                        }
                        ));
                }
                else
                {
                    mDataView.DataSource = GenerateTempBinding(AssemblyHelper.Load(mTxt_PathName.Text).Interfaces.ConvertAll(
                        n => new
                        {
                            Name = n.Name,
                            AssemblyName = n.AssemblyName,
                            NameSpace = n.Namespace,
                            FullName = n.FullName,
                        }
                        ));
                }
            }
            catch (FileNotFoundException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private string GetInterfaceNames(ClassEntity classEntity)
        {
            return string.Join(", ", classEntity.ImplementedInterfaces.ConvertAll(n => n.FullName).ToArray());
        }

        private BindingList<T> GenerateTempBinding<T>(List<T> list)
        {
            return new BindingList<T>(list);
        }
    }
}
